<template>
  <div class="login_wrap">
    <div class="header">
      <a href="http://192.168.3.67/Advertiser_Mall/weijifen/home.html" class="am-block am-fl">
        <img src="../assets/images/w-logo.png" alt="">
      </a>
      <span class="am-fr">欢迎登录</span>
    </div>
    <div class="content">
      <div class="banner am-fl">
        <img src="../assets/images/loginPageHome.png" alt="">
      </div>
      <div class="login_box am-fr">
          <div class="title">广告主</div>
            <form action="" class="am-form am-form-inline">
              <div class="am-form-group am-form-icon">
                <i class="am-icon-mobile">
                  <img src="../assets/images/usernameIcon.png" alt="">
                </i>
                <input type="text" class="am-form-field am-input-sm" placeholder="公司名称/小毛驴账号/邮箱"
                v-model="username">
              </div>
            </form>
            <form action="" class="am-form am-form-inline">
              <div class="am-form-group am-form-icon">
                <i class="am-icon-lock">
                  <img src="../assets/images/passwordIcon.png" alt="">
                </i>
                <input type="password" class="am-form-field am-input-sm" placeholder="密码" v-model="password">
              </div>
            </form>
            <div class="remember">
              <label for="" class="cursorPoint" @click="handleRemember()">
                <img src="../assets/images/circle1.png" alt="" v-if="remember">
                <img src="../assets/images/circle.png" alt="" v-else>
                <span class="fontNormal">记住密码</span>
              </label>
              <p class="error_cue am-text-danger"
                 :style="{opacity:error_cue?'1':'0'}" v-text="error_cue"></p>
            </div>
            <button class="loginSubmitBtn" @click="handleLogin()">登&nbsp;&nbsp;录</button>
      </div>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
import '../assets/css/login.css'
import {url} from '../../static/config'

axios.defaults.withCredentials = true
axios.defaults.headers['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'

export default {
  name: 'Login',
  data () {
    return {
      username: '',
      password: '',
      remember: false,
      error_cue: ''
    }
  },
  created () {
    var _this = this
    axios.post(url + '/web-adv/getUser')
      .then(function (res) {
        console.log('获取密码', res)
        _this.username = res.data.username
        _this.password = res.data.password
        _this.remember = !!res.data.username
      })
  },
  methods: {
    handleRemember () {
      this.remember = !this.remember
    },
    handleLogin () {
      if (!this.username || !this.password) {
        this.error_cue = '账号或密码不能为空!'
      } else {
        this.error_cue = ''
        var _this = this
        // flag赋值{TO_DO}
        axios.post(url + '/web-adv/dologin?memberName=' + _this.username + '&password=' + _this.password +
        '&rememberMe=' + _this.remember + '&flag=')
          .then(function (res) {
            // console.log('登录', res.data)
            if (res.data.status === 1) {
              window.location.href = '/aialrs/adalready?kind=0'
            } else {
              _this.error_cue = res.data.error
            }
          }).catch(function (err) {
            console.log(err)
          })
      }
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
